Skip to content

fix(id-web): reject malformed bracketed IPv6 Host authorities (#8776) - #8797

Merged
dezren39 merged 2 commits into
mainfrom
queue/15033-8776-host-bracket-fix
Nov 11, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/15033-8776-host-bracket-fix

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Fixes #8776. Queue task 15033 (lane code-a).

The bug

host_only in pkgs/id/src/web/security.rs handled any authority starting with [ by returning the text before the first ], without validating the remainder. The loopback Host guard then compared only that prefix against allowed_hosts, so Host: [::1]attacker.example reduced to ::1 and passed the loopback allow-list — as did the unterminated [::1.

The fix

host_only now validates the complete bracketed authority before extracting the host: only an empty tail or a : + numeric port may follow the closing bracket. A malformed bracketed authority (trailing host text, non-numeric or empty port, missing closing bracket) returns the full authority text, which matches no allowed host, so the guard refuses it with MISDIRECTED_REQUEST (421). Scope is confined to host_only; no Origin-parsing changes.

Tests

Two regression tests added in web::security::tests:

  • host_only_rejects_malformed_bracketed_authorities — malformed forms ([::1]attacker.example, [::1]attacker.example:3000, [::1]:abc, [::1]:, [::1, [::1]]) must not reduce to ::1; valid [::1] and [::1]:3000 still extract ::1.
  • malformed_bracketed_host_is_refused — the guarded router returns 421 for malformed bracketed hosts and 200 for the valid controls.

Verification note (pre-existing breakage)

The pkgs/id lib does not compile on current main with the web feature (5 pre-existing errors in src/web/routes.rs, explore.rs, world_ws.rs — crate-split visibility fallout, proven identical on a pristine worktree of e6889a3 and filed as #8795), so the in-tree lib tests cannot run yet. The tests above were therefore run in a probe harness that compiles the real security.rs by path:

  • Before the fix: both new tests FAIL ([::1]attacker.example got 200 instead of 421; host_only returned ::1), the other 17 security tests pass.
  • After the fix: 19/19 pass.
  • cargo check -p id --lib --all-features on this branch reports exactly the same 5 pre-existing errors as pristine main — no new errors, none in security.rs. rustfmt --check on the file is clean.

Once #8795 lands, these tests run in-tree with the rest of the web::security suite.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 23:20
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5c7150e4-f771-469e-be00-15fdc8b012be
Commits

Reviewing files that changed from the base of the PR and between 160e2d6 and c72d639.

Files selected for processing: 1

  • pkgs/id/src/web/security.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T23:30:55.380710Z c72d639 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39 dezren39 added kind/security Security issue or security hardening task/small-fix Queue packet kind: bounded fix with reproduction and targeted tests labels Nov 11, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5be8434eec

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +324 to +328
for malformed in [
"[::1]attacker.example",
"[::1]attacker.example:3000",
"[::1]:abc",
"[::1]:",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Cover the authority parser invariant with property-based tests

The new test states a meaningful parser invariant—malformed bracketed authorities must not collapse to an allowed host—but checks only six fixed examples. Root AGENTS.md explicitly requires property-based coverage for parser invariants, and proptest is already a dev-dependency of this package. Add generated valid authorities and malformed suffix/delimiter variants to check the invariant, retaining these examples as regression smoke tests.

AGENTS.md reference: AGENTS.md:L42-L42

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in follow-up commit c72d639 on this branch: added a proptest block in web::security::tests covering the invariant directly —

  • bracketed_authority_collapses_only_for_valid_tails: generated hosts (::1, ::, fe80::1, 2001:db8::1) × generated printable-ASCII tails (0–12 chars); the oracle restates the invariant — host_only returns the bracketed host only when the tail is empty or : + a non-empty all-digit port, and never otherwise. The six fixed examples stay as regression smoke tests and are referenced as such.
  • bracketed_authority_with_numeric_port_always_extracts_host: generated u16 ports always extract the host, as does the bare bracketed form.

Verified in the probe harness that compiles the real security.rs (the in-tree lib target is blocked by the pre-existing #8795 compile breakage): 21/21 tests pass, including both new properties at 128 cases.

@dezren39
dezren39 merged commit 4eb2399 into main Nov 11, 2026
3 of 12 checks passed
@dezren39
dezren39 deleted the queue/15033-8776-host-bracket-fix branch November 11, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/security Security issue or security hardening task/small-fix Queue packet kind: bounded fix with reproduction and targeted tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id(web): reject malformed bracketed IPv6 Host authorities

1 participant